package com.zh.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.zh.pojo.dto.LocationDto;
import com.zh.pojo.dto.WxMinAppRegisterDto;
import com.zh.result.JSONResult;
import com.zh.service.IDriverService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Tag(name = "司机对象",description = "司机对象")
@RestController
@RequestMapping("/app/driver")
public class AppDriverController {

    @Autowired
    public IDriverService driverService;

    @Operation( summary= "小程序微信司机注册",description = "小程序微信司机注册接口")
    @Parameter(name = "driver",description = "注册的对象",required = true)
    @PostMapping("/wxregister")
    // 此接口加上了 @SaIgnore 可以游客访问
    @SaIgnore
    public JSONResult save(@RequestBody @Valid WxMinAppRegisterDto wxRegisterDto){
        driverService.wxregister(wxRegisterDto);
        return JSONResult.success();
    }

    @Operation( summary= "查询司机工作台信息",description = "查询司机工作台信息")
    @GetMapping(value = "/loading/workbench")
    public JSONResult selectByDriverWorkbench(){
        return JSONResult.success(driverService.selectByDriverWorkbench());
    }
    @Operation( summary= "开始接单",description = "开始接单")
    @PostMapping(value = "/startReceivingOrders")
    public JSONResult startReceivingOrders(){
        driverService.startReceivingOrders();
        return JSONResult.success();
    }
    @Operation( summary= "停止接单",description = "停止接单")
    @PostMapping(value = "/stopReceivingOrders")
    public JSONResult stopReceivingOrders(){
        driverService.stopReceivingOrders();
        return JSONResult.success();
    }
    @Operation( summary= "将司机坐标缓存到GEO",description = "将司机坐标缓存到GEO")
    @PostMapping(value = "/cache/location/geo")
    public JSONResult cacheLocationGeo(@RequestBody @Valid LocationDto locationDto){
        driverService.cacheLocationGeo(locationDto);
        return JSONResult.success();
    }

}
